|
1
|
|
|
/** |
|
2
|
|
|
* nextCloud - ocr |
|
3
|
|
|
* |
|
4
|
|
|
* This file is licensed under the Affero General Public License version 3 or |
|
5
|
|
|
* later. See the COPYING file. |
|
6
|
|
|
* |
|
7
|
|
|
* @author Janis Koehr <[email protected]> |
|
8
|
|
|
* @copyright Janis Koehr 2017 |
|
9
|
|
|
*/ |
|
10
|
|
|
|
|
11
|
|
|
/* global Backbone, Handlebars */ |
|
12
|
|
|
(function (OC, Backbone, Handlebars, $) { |
|
13
|
|
|
'use strict'; |
|
14
|
|
|
|
|
15
|
|
|
OC.Settings = OC.Settings || {}; |
|
16
|
|
|
OC.Settings.Ocr = OC.Settings.Ocr || {}; |
|
17
|
|
|
|
|
18
|
|
|
var TEMPLATE = '{{#if enabled}}' |
|
19
|
|
|
+ ' <table class="grid ocrsettings">' |
|
|
|
|
|
|
20
|
|
|
+ ' <thead>' |
|
|
|
|
|
|
21
|
|
|
+ ' <tr>' |
|
|
|
|
|
|
22
|
|
|
+ ' <th>' + t('ocr', 'Name') + '</th>' |
|
|
|
|
|
|
23
|
|
|
+ ' <th>' + t('ocr', 'Status') + '</th>' |
|
|
|
|
|
|
24
|
|
|
+ ' <th>' + t('ocr', 'Delete from queue') + '</th>' |
|
|
|
|
|
|
25
|
|
|
+ ' </tr>' |
|
|
|
|
|
|
26
|
|
|
+ ' </thead>' |
|
|
|
|
|
|
27
|
|
|
+ ' <tbody>' |
|
|
|
|
|
|
28
|
|
|
+ ' {{#each status}}' |
|
|
|
|
|
|
29
|
|
|
+ ' <tr data-id="{{ id }}">' |
|
|
|
|
|
|
30
|
|
|
+ ' <td>{{ target }}</td>' |
|
|
|
|
|
|
31
|
|
|
+ ' <td>{{ status }}</td>' |
|
|
|
|
|
|
32
|
|
|
+ ' <td class="ocr-action-delete"><div id="ocr-delete"><span>' + t('ocr', 'Delete') + '</span><span class="icon icon-delete"></span></div></td>' |
|
|
|
|
|
|
33
|
|
|
+ ' </tr>' |
|
|
|
|
|
|
34
|
|
|
+ ' {{/each}}' |
|
|
|
|
|
|
35
|
|
|
+ ' </tbody>' |
|
|
|
|
|
|
36
|
|
|
+ ' </table>' |
|
|
|
|
|
|
37
|
|
|
+ ' {{else}}' |
|
|
|
|
|
|
38
|
|
|
+ ' <p>' + t('ocr' , 'No pending or failed OCR items found.') +'</p>' |
|
|
|
|
|
|
39
|
|
|
+ ' {{/if}}' |
|
|
|
|
|
|
40
|
|
|
+ '<button id="ocr-search">' + t('ocr', 'Refresh') + '</button>'; |
|
|
|
|
|
|
41
|
|
|
|
|
42
|
|
|
var View; |
|
43
|
|
|
View = Backbone.View.extend({ |
|
44
|
|
|
template: Handlebars.compile(TEMPLATE), |
|
45
|
|
|
_loading: undefined, |
|
46
|
|
|
_enabled: undefined, |
|
47
|
|
|
events: { |
|
48
|
|
|
'click #ocr-search': '_load', |
|
49
|
|
|
'click #ocr-delete': '_delete' |
|
50
|
|
|
}, |
|
51
|
|
|
initialize: function () { |
|
52
|
|
|
this._load(); |
|
53
|
|
|
}, |
|
54
|
|
|
render: function (data) { |
|
55
|
|
|
this.$el.html(this.template(data)); |
|
56
|
|
|
}, |
|
57
|
|
|
_load: function () { |
|
58
|
|
|
if (this._loading) { |
|
59
|
|
|
//ignore when loading |
|
60
|
|
|
return; |
|
61
|
|
|
} |
|
62
|
|
|
this._loading = true; |
|
63
|
|
|
|
|
64
|
|
|
var url = OC.generateUrl('/apps/ocr/settings/personal'); |
|
65
|
|
|
var loading = $.ajax(url, { |
|
66
|
|
|
method: 'GET' |
|
67
|
|
|
}); |
|
68
|
|
|
|
|
69
|
|
|
var _this = this; |
|
70
|
|
|
$.when(loading).done(function (status) { |
|
71
|
|
|
if (status.length > 0) { |
|
72
|
|
|
_this._enabled = true; |
|
73
|
|
|
_this._showTable(status); |
|
74
|
|
|
} else { |
|
75
|
|
|
_this._enabled = false; |
|
76
|
|
|
_this._showTable(); |
|
77
|
|
|
} |
|
78
|
|
|
}); |
|
79
|
|
|
$.when(loading).always(function () { |
|
80
|
|
|
_this._loading = false; |
|
81
|
|
|
}); |
|
82
|
|
|
}, |
|
83
|
|
|
_delete: function(e) { |
|
84
|
|
|
if (this._loading) { |
|
85
|
|
|
//ignore when loading |
|
86
|
|
|
return; |
|
87
|
|
|
} |
|
88
|
|
|
this._loading = true; |
|
89
|
|
|
var _this = this; |
|
90
|
|
|
var url = OC.generateUrl('/apps/ocr/settings/personal'); |
|
91
|
|
|
var deleting = $.ajax(url, { |
|
92
|
|
|
method: 'DELETE', |
|
93
|
|
|
data: { |
|
94
|
|
|
id: $(e.target).closest('tr').data('id') |
|
95
|
|
|
} |
|
96
|
|
|
}); |
|
97
|
|
|
|
|
98
|
|
|
$.when(deleting).done(function(data) { |
|
99
|
|
|
_this._showMsg(t('ocr', 'Following file has been successfully deleted from the queue:') + ' "' + data.target + '"'); |
|
100
|
|
|
_this._loading = false; |
|
101
|
|
|
_this._load(); |
|
102
|
|
|
}); |
|
103
|
|
|
|
|
104
|
|
|
$.when(deleting).fail(function(jqXHR) { |
|
105
|
|
|
_this._showMsg(t('ocr', 'Error during deletion: ') + jqXHR.responseText); |
|
106
|
|
|
_this._loading = false; |
|
107
|
|
|
}); |
|
108
|
|
|
|
|
109
|
|
|
}, |
|
110
|
|
|
_showTable: function(data) { |
|
111
|
|
|
var _this = this; |
|
112
|
|
|
this.render({ |
|
113
|
|
|
enabled: _this._enabled, |
|
114
|
|
|
status: data |
|
115
|
|
|
}); |
|
116
|
|
|
}, |
|
117
|
|
|
_showMsg: function (msg) { |
|
118
|
|
|
$('#ocr-msg').text(msg); |
|
119
|
|
|
setTimeout(function() { $('#ocr-msg').text(''); }, 5000); |
|
120
|
|
|
} |
|
121
|
|
|
}); |
|
122
|
|
|
|
|
123
|
|
|
OC.Settings.Ocr.View = View; |
|
124
|
|
|
|
|
125
|
|
|
})(OC, Backbone, Handlebars, $); |
|
|
|
|
|